path = './test03.txt'
try:
    f_name = open(file=path, mode='w', buffering=1, encoding='utf-8')
    count01 = f_name.write('我爱你中国')
    print(f'{f_name.name}写入完成,写入了{count01}个字符')
    f_name = open(file=path, mode='a', buffering=1, encoding='utf-8')
    count02 = f_name.write('亲爱的母亲')
    print(f'{f_name.name}内容追加完成,追加了{count02}个字符')
finally:
    # 关闭文件
    f_name.close()

with open(file=path, mode='a', buffering=1, encoding='utf-8') as f:
    count = f.write('\n桃李不言下自成蹊')
    print(f'{f.name}内容追加完成,追加了{count}个字符')
